package jp.co.kayo.gae.takidashibot.utils;

import java.util.Comparator;

public class MyComparator implements Comparator<TakidasiPair> {
    int n;
    public MyComparator(int range){
        if(range>0){
            n = range/100;
        }
        else{
            n = 1;
        }
    }

    @Override
    public int compare(TakidasiPair o1, TakidasiPair o2) {
        double d1 = o1.dist/n;
        double d2 = o2.dist/n;
        double d = d1 - d2;
        if(d<0){
            return -1;
        }
        else if(Math.abs(d)<1){
            long t = o2.takidasi.getCreatedAt() - o1.takidasi.getCreatedAt();
            if(t<0){
                return -1;
            }
            else if(t == 0){
                return 0;
            }
            else{
                return 1;
            }
        }
        else{
            return 1;
        }
    }

}
